package com.lagou;

import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;

/**
 * 过滤获取调用方ip
 */
@Activate(group = {CommonConstants.PROVIDER})
public class IpFilter implements Filter {
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        //从RPCcontext获取ip
        String remoteHost = RpcContext.getContext().getRemoteHost();
        System.out.println("调用方ip为："+remoteHost);
        return invoker.invoke(invocation);
    }
}
